<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/header.css" rel="stylesheet" />
		<style>
			
			#scan_Component {
				position: absolute;
				width: 100%;
				top: 44px;
				bottom: 0px;
				text-align: center;
				background: black;
			}
			
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<h1 class="mui-title title-color">扫一扫</h1>
		</header>
		
		<div id="scan_Component">

		</div>
	
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js" type="text/javascript" ></script>
		<script type="text/javascript">
			mui.init({
				swipeBack:true //启用右滑关闭功能
			});
			mui.plusReady(function() {
				setTimeout(()=>{
					statrScan();
				},100)	
			});
			var scan;
			function statrScan(){
				
				var styles = {
					background: "",
					frameColor: "#34CE57",
					scanbarColor: "#fff"
				}
	
				scan = new plus.barcode.Barcode('scan_Component',null,styles);
				scan.onmarked = onmarked; 
				scan.start();
			}
			function onmarked( type, result ) {
				if(type === 0){
					var content = result.split("wechat_qrcode:");
					if(content.length != 2){
						app.showToast("识别出错啦...", "error");
						
							mui.openWindow("../index.html", "index.html");
					}else{
						go_friend_info(content[1]);
					}
				}
			
			}
			function go_friend_info(userName){
				var fr_user_info = app.getUserInfo();
				plus.nativeUI.showWaiting("请稍等");
				var url = app.serverUrl + '/u/searchUser?friendUserName=' + userName + '&myUserId=' + fr_user_info.userId;
			    	mui.ajax(url,{
					dataType:'json',//服务器返回json格式数据
					type:'post',//HTTP请求类型
					timeout:10000,//超时时间设置为10秒；
					headers:{'Content-Type':'application/json'},	              
					success:function(data){
						plus.nativeUI.closeWaiting();
						if(data.status == 200){
							var userInfo = data.data;
							mui.openWindow({
								url: "../discover/friend_info.html",
							    id: "friend_info.html",
							    extras:{
							      friendInfo:userInfo,
							      fr_user_info:fr_user_info
							    },
							});
						}else{
							app.showToast(data.msg, "error");
							mui.back();
						}
					},
					error:function(xhr,type,errorThrown){
						app.Error();
					}
				});
			}
		</script>
	</body>
</html>
